<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib  prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="redis" uri="http://www.shopjsp.com/redisTag/functions" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<c:set var="basePath" value="${redis:getSysConfig('base_path_back')}"/>
<c:set var="srcPath" value="${redis:getSysConfig('sysFileVisitRoot_back')}"/>
<c:set var="commissionProportion" value="${redis:getSysConfig('commissionProportion')}"/>
<c:set var="uploadPath" value="${redis:getSysConfig('uploadFileVisitRoot')}"/>
<script type="text/javascript">
    /**
     * 表单提交及验证初始化
     */
    var form_check;
    $(document).ready(function() {
        form_check=$("#form_check");
        if(form_check.length>0){ /**判断当前页面是否有填写表单并检验**/
        validateFormCheck();
            /**Modal验证销毁重构**/
            $('#checkModal').on('hidden.bs.modal', function() {
                reValidateFormCheck();
            });
        }
    });

    /**
     * 重置表单验证
     */
    function reValidateFormCheck(){
        form_check.data('bootstrapValidator', null);
        validateFormCheck();
    }

    /**
     * 自定义验证规则
     */
    function validateFormCheck(){
        form_check.bootstrapValidator({
            message: "无效的值",
            feedbackIcons: {
                valid: "glyphicon glyphicon-ok",
                invalid: "glyphicon glyphicon-remove",
                validating: "glyphicon glyphicon-refresh"
            },
            fields: {
                commission: {
                    validators: {
                        notEmpty: {message: "佣金抽成不可为空"},
                        stringLength: {max: 2, message: "佣金抽成最高99"},
                        regexp: {
                            regexp:validateUtil.positiveInteger,
                            message: "只能填写正整数"
                        }
                    }
                }
            }
        });
    }

    /**
     * 审核店铺信息
     */
	<shiro:hasPermission name="back_gotoEnterShopInfoPage_check">
    function check() {
        /**获取选中行的id**/
        var selectedRow = $("#tt").bootstrapTable('getSelections');
        if (selectedRow.length == 1) {
            var id = selectedRow[0].shopInfoId;
            $("#btn_check").attr("data-target", "#checkModal");/**选中了记录后才可打开对应的模态框**/
            $.ajax({
                type: "POST",
                dataType: "JSON",
                url: "${basePath}/back/enterShopInfo/getShopInfoObject.sjson",
                data: {shopInfoId: id},
                success: function (result) {
                    var data = JSON.parse(result.data);
                    var shopInfo = data.shopInfo;
                    /**重置详情页中所有html展示信息**/
                    resetDetailTable("detailTableCheck");
                    /**设置展示信息**/
                    $("#p_shopInfoId").val(shopInfo.shopInfoId);
                    $("#p_customerId").html(shopInfo.customerName);
                    $("#p_categoryName").html(data.categoryName);
                    $("#p_shopName").html(shopInfo.shopName);
                    $("#p_postCode").html(shopInfo.postCode);
                    $("#p_phone").html(shopInfo.phone);
                    $("#p_postage").html(shopInfo.postage+"元");
                    $("#p_minAmount").html("满"+shopInfo.minAmount+"元包邮");
                    $("#p_address").html(shopInfo.address);
                    $("#p_mainProduct").html(shopInfo.mainProduct);
                    $("#p_logoUrl").html("<img id='uploadImg_detail_6' class='uploadImg' onMouseOver='showDetailBigImage(6,3,3,0)'  onMouseOut='showDetailRebackImage(6,1,1)' src='${uploadPath}/"+shopInfo.logoUrl+"' onerror='this.src=\"${srcPath}/common/images/mrbj.png\"' width='50px' height='50px' />");
                    $("#p_bannerUrl").html("<img id='uploadImg_detail_7' class='uploadImg' onMouseOver='showDetailBigImage(7,3,3,0)'  onMouseOut='showDetailRebackImage(7,1,1)' src='${uploadPath}/"+shopInfo.bannerUrl+"' onerror='this.src=\"${srcPath}/common/images/mrbj.png\"' width='50px' height='50px' />");
                    $("#p_companyName").html(shopInfo.companyName);
                    if(shopInfo.phoneShowStatus != ""&&shopInfo.phoneShowStatus != null&&shopInfo.phoneShowStatus != undefined){
                        $("#p_phoneShowStatus_"+shopInfo.phoneShowStatus).attr("checked","checked");
                    }else {
                        $("#p_phoneShowStatus_0").attr("checked","checked");
                    }
                    if(shopInfo.commission != "" && shopInfo.commission != null && shopInfo.commission != undefined){
                        $("#p_commission").val(shopInfo.commission);
                    }else{
                        $("#p_commission").val(${commissionProportion});//从redis中取默认佣金抽成
                    }
                    $("#p_isPass_"+shopInfo.isPass).attr("checked","checked");
                }
            });
        } else {
            $("#btn_check").attr("data-target", "");/**没有选中记录不可打开模态框**/
            showMsg("请选择一行记录！");
        }
    }
	</shiro:hasPermission>

    /**
     * 表单异步提交
     */
    function submitFormCheck(){
        /** 开启验证**/
        form_check.data('bootstrapValidator').validate().validate();
        var isValid=form_check.data('bootstrapValidator').isValid();
        if(isValid){  /** 验证通过后提交表单**/
        var options = {
                url: form_check.attr("action"),
                type : "post",
                dataType:"json",
                success : function(data) {
                    if(data.success==true){
                        /** 先重置查询框的值**/
                        resetQueryForm();
                        /** 重新刷新列表数据**/
                        $("#tt").bootstrapTable('refresh');
                        /** 自动关闭弹出模态框窗口**/
                        $(".close").click();
                        showMsg("保存成功！");
                    }else{
                        showMsg("保存失败！");
                    }
                }
            };
            form_check.ajaxSubmit(options);
        }else{ /** 验证失败了直接返回 **/
            return false;
        }
    }

</script>

<!--添加编辑模态框（Modal） -->
<div class="modal fade" id="checkModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" data-backdrop="static" >
	<div class="modal-dialog" style="width:70%">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
				<h5 class="modal-title" id="myModalLabel">入驻店铺审核</h5>
			</div>
			<div class="modal-body">
				<form id="form_check" method="post" action="${basePath}/back/enterShopInfo/saveCheckShopInfo.sjson">
					<input id="p_shopInfoId" type="hidden" name="shopInfoId" value=""/>
					<table id="detailTableCheck" align="center" class="addOrEditTable table-bordered table" style="width:100%;">

						<tr>
							<td class="toright_td" width="150px">店铺Logo:</td><td  class="toleft_td" width="250px">&nbsp;&nbsp;<span id="p_logoUrl"></span></td>
							<td class="toright_td" width="150px">店铺首页大图:</td><td  class="toleft_td" width="250px">&nbsp;&nbsp;<span id="p_bannerUrl"></span></td>
						</tr>
						<tr>
							<td class="toright_td">店铺账号:</td><td class="toleft_td">&nbsp;&nbsp;<span id="p_customerId"></span></td>
							<td class="toright_td">公司名称:</td><td class="toleft_td">&nbsp;&nbsp;<span id="p_companyName"></span></td>
						</tr>
						<tr>
							<td class="toright_td">公司地址:</td><td class="toleft_td">&nbsp;&nbsp;<span id="p_address"></span></td>
							<td class="toright_td">邮政编码:</td><td class="toleft_td">&nbsp;&nbsp;<span id="p_postCode"></span></td>
						</tr>
						<tr>
							<td class="toright_td">店铺分类:</td><td class="toleft_td">&nbsp;&nbsp;<span id="p_categoryName"></span></td>
							<td class="toright_td">店铺名称:</td><td class="toleft_td">&nbsp;&nbsp;<span id="p_shopName"></span></td>
						</tr>
						<tr>
							<td class="toright_td">联系电话:</td><td class="toleft_td">&nbsp;&nbsp;<span id="p_phone"></span></td>
							<td class="toright_td">主要销售产品:</td><td class="toleft_td">&nbsp;&nbsp;<span id="p_mainProduct"></span></td>
						</tr>
						<tr>
							<td class="toright_td">运费:</td><td class="toleft_td">&nbsp;&nbsp;<span id="p_postage"></span></td>
							<td class="toright_td">订单满额包邮:</td><td class="toleft_td">&nbsp;&nbsp;<span id="p_minAmount"></span></td>
						</tr>
						<tr>
							<td class="toright_td"><span style="color:red">* </span>是否展示联系电话:</td>
							<td class="toleft_td">
								<label class="checkbox-inline"><input type="radio" name="phoneShowStatus" id="p_phoneShowStatus_0" class="radioInput" value="0">未展示</label>
								<label class="checkbox-inline"><input type="radio" name="phoneShowStatus" id="p_phoneShowStatus_1" class="radioInput" value="1">已展示</label>
							</td>
							<td class="toright_td"><span style="color:red">* </span>设置佣金抽成（%）:</td>
							<td class="toleft_td">
								<div class="form-group">
									<input type="text" id="p_commission" name="commission" class="form-control input-sm" placeholder="请输入佣金抽成" width=""/>
								</div>
							</td>
						</tr>
						<tr>
							<td class="toright_td" width="140px"><span style="color:red">* </span>店铺审核状态:&nbsp;&nbsp;</td>
							<td  class="toleft_td" colspan="3">
								<label class="checkbox-inline"><input type="radio" name="isPass" id="p_isPass_1" class="radioInput" value="1">待审核</label>
								<label class="checkbox-inline"><input type="radio" name="isPass" id="p_isPass_2" class="radioInput" value="2">未通过</label>
								<label class="checkbox-inline"><input type="radio" name="isPass" id="p_isPass_3" class="radioInput" value="3">已通过</label>
							</td>
						</tr>
					</table>
				</form>
			</div>
			<div class="modal-footer">
				<button type="button" id="validateBtn" class="btn btn-primary"  onclick="submitFormCheck()">保存</button>
				<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
			</div>
		</div><!-- /.modal-content -->
	</div><!-- /.modal -->
</div>
